rm -rf output
mkdir output

cho "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "[INFO]开始更新代码......远端代码将会完全覆盖本地代码"
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"

git reset --hard
git pull

echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "[INFO]开始Maven打包......"
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
mvn clean package -Dmaven.test.skip=true

if [ $? -ne 0 ]; then
    echo ""
    echo "***********************************************************"
    echo "[INFO]Maven打包失败"
    echo "***********************************************************"
    exit 1
fi
cp Dockerfile output/Dockerfile
cp target/vas-1.0-SNAPSHOT.jar output/vas.jar

docker stop vas
docker rm vas
docker rmi vas:0.0.1

echo '>>> old container removed'

echo '================开始构建镜像================'
cd output
docker build -t vas:0.0.1 .
echo '================结束构建镜像================'


echo '================开始运行新容器================'
docker run -itd -p 8111:8111 --restart always --name=vas --privileged=true vas:0.0.1
docker run -itd -p 8112:8111 --restart always --name=vas --privileged=true vas:0.0.1
echo '================运行新容器完毕================'


echo '================结束远程启动================'
